﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IPC.LogCommon.log4net;

namespace IPC.DbMapper.IPCDBConnect
{
    public class IPCDbContext : DbContext
    {
        #region 声明表
        /// <summary>
        /// 通道
        /// </summary>
        public DbSet<Channel> Channels { get; set; }
        /// <summary>
        /// 设备
        /// </summary>
        public DbSet<Equip> Equips { get; set; }
        /// <summary>
        /// 组
        /// </summary>
        public DbSet<Group> Groups { get; set; }
        /// <summary>
        /// 标签
        /// </summary>
        public DbSet<Tag> Tags { get; set; }

        /// <summary>
        /// 系统配置
        /// </summary>
        public DbSet<SystemConfig> SystemConfigs { get; set; }
        #endregion

        //连接字符串
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            try
            {
                //base.OnConfiguring(optionsBuilder);
                optionsBuilder.UseSqlite($"DataSource={System.Environment.CurrentDirectory}/IPC.db");
                //LogClass.Instance.Info("数据库连接初始化");
            }
            catch(Exception ex)
            {
                LogClass.Instance.Error($"数据库连接初始化失败{ex.Message}");
            }
        }
    }
}
